using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using Microsoft.DirectX.DirectDraw;
using TowerDefense_Dx.Core;

namespace TowerDefense_Dx.GameLogic
{
    public class Bullet:DxSprite
    {
        private double _angle;
        private double X, Y;
        private float _bulletSpeed = 10;
        private bool _isDead = false;
        public bool IsDead
        {
            get { return _isDead; }
            set { _isDead = value; }
        }
        public Bullet(string imagePath, Device graphicDevice, int frameWidth, int frameHeight, PointF position,float bulletAngle)
            : base(imagePath, graphicDevice, frameWidth, frameHeight)
        {
            _angle = bulletAngle;
            _position = position;
            _center.X = _position.X + (_frameWidth / 2);
            _center.Y = _position.Y + (_frameHeight / 2);
        }
        public void Update()
        {
            X = _position.X;
            Y = _position.Y;

            X = X + _bulletSpeed * Math.Cos(_angle * Math.PI / 180);
            Y = Y + _bulletSpeed * Math.Sin(_angle * Math.PI / 180);

            _position.X = (float)X;
            _position.Y = (float)Y;
            _center.X = _position.X + (_frameWidth / 2);
            _center.Y = _position.Y + (_frameHeight / 2);
        }
        public void CheckColison(Enemy target, int damage)
        {
            if (target != null)
            {
               // PointF newTargetPos = new PointF(target.Position.X + 3, target.Position.Y + 96);
                RectangleF boudingBox1 = new RectangleF(this.Position, new Size(_frameWidth, _frameHeight));
                RectangleF boudingBox2 = new RectangleF(target.Position, new Size(target.FrameWidth, target.FrameHeight));
                if (boudingBox1.IntersectsWith(boudingBox2))
                {
                    this._isDead = true;
                    target.GetHit(damage);
                }
                
            }
        }
	
    }
}
